package com.yurun.service.impl;

import com.yurun.entity.VisitLog;
import com.yurun.exception.PersistenceException;
import com.yurun.mapper.VisitLogMapper;
import com.yurun.model.dto.VisitLogUuidTime;
import com.yurun.service.VisitLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisitLogServiceImpl implements VisitLogService {
    @Autowired
    VisitLogMapper visitLogMapper;

    @Override
    public void addVisitLog(VisitLog visitLog){
        if(visitLogMapper.addVisitLog(visitLog)!=1){
            throw new PersistenceException("添加访问日志失败");
        }
    }

    @Override
    public void deleteVisitLogById(Long id){
        if(visitLogMapper.deleteVisitLogById(id)!=1){
            throw new PersistenceException("删除访问日志失败");
        }
    }

    @Override
    public List<VisitLog> getVisitLogListByUUIDAndDate(String uuid, String startDate, String endDate){
        return visitLogMapper.getVisitLogListByUUIDAndDate(uuid, startDate, endDate);
    }

    @Override
    public List<VisitLogUuidTime> getUUIDAndCreateTimeByYesterday(){
        return visitLogMapper.getUUIDAndCreateTimeByYesterday();
    }

    @Override
    public int countVisitLogByToday(){
        return visitLogMapper.countVisitLogByToday();
    }
}
